package com.origin.uilibrary.progres_bar

import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.ScaleDrawable
import android.view.Gravity
import android.widget.SeekBar
import com.origin.uilibrary.SelectorFactory

/**
 * @param backgroundColor 背景色
 * @param secondaryProgressColor 二级背景
 * @param progressColor 进度条
 * @param radius 圆角
 * @param thumb 指示器
 */
public fun SeekBar.setProgressDrawableAndThumb(backgroundColor: Int, secondaryProgressColor: Int, progressColor: Int, radius: Int, thumb: Drawable) {
    val backgroundDrawable = SelectorFactory.newShapeSelector().setCornerRadius(radius).setDefaultBgColor(backgroundColor).create()
    val secondaryProgressDrawable = SelectorFactory.newShapeSelector().setCornerRadius(radius).setDefaultBgColor(secondaryProgressColor).create()
    val progressProgressDrawable = SelectorFactory.newShapeSelector().setCornerRadius(radius).setDefaultBgColor(progressColor).create()

    val secProgressDr: Drawable = ScaleDrawable(secondaryProgressDrawable, Gravity.FILL_VERTICAL or Gravity.START, 1f, 1f)
    val progressDr: Drawable = ScaleDrawable(progressProgressDrawable, Gravity.FILL_VERTICAL or Gravity.START, 1f, 1f)

    val resultDr = LayerDrawable(arrayOf(backgroundDrawable, secProgressDr, progressDr))

    resultDr.setId(0, android.R.id.background)
    resultDr.setId(1, android.R.id.secondaryProgress)
    resultDr.setId(2, android.R.id.progress)
    this.progressDrawable = resultDr
    this.thumb = thumb

}
